import java.time.Duration;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: D3
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/10 16:42
 */
public class D3 {
    public static void main(String[] args) {
        LocalDate ldt1 = LocalDate.of(2020, 5, 4);
        LocalDate ldt2 = LocalDate.now();
        //计算时间差值
        System.out.println("方式1相差：" + ldt1.until(ldt2, ChronoUnit.DAYS));

        System.out.println("方式2相差：" + Duration.between(ldt1.atStartOfDay(), ldt2.atStartOfDay()).toDays());

        System.out.println("方式3相差：" + ChronoUnit.DAYS.between(ldt1, ldt2));
        //年月日分别相差
        Period period = Period.between(ldt1, ldt2);
        System.out.println("方式4相差：" + period.getYears() + "年" + period.getMonths() + "个月" + period.getDays() + "天");
    }
}
